<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="报废资产id" prop="declaredAssetId">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredAssetId"-->
<!--          placeholder="请输入报废资产id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="报废资产" prop="declaredAssetName">
        <el-input
          v-model="queryParams.declaredAssetName"
          placeholder="请输入报废资产名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="报废资产类别名称" prop="declaredAssetClassName">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredAssetClassName"-->
<!--          placeholder="请输入报废资产类别名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="品牌" prop="assetBrand">-->
<!--        <el-input-->
<!--          v-model="queryParams.assetBrand"-->
<!--          placeholder="请输入品牌"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="规格型号" prop="assetModel">-->
<!--        <el-input-->
<!--          v-model="queryParams.assetModel"-->
<!--          placeholder="请输入规格型号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="数量" prop="declaredQuantity">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredQuantity"-->
<!--          placeholder="请输入数量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="报废时间" prop="declaredTime">
        <el-date-picker clearable
          v-model="queryParams.declaredTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择报废时间">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="报废领用信息id" prop="declaredReceiveId">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredReceiveId"-->
<!--          placeholder="请输入报废领用信息id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="报废负责人id" prop="declaredRespId">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredRespId"-->
<!--          placeholder="请输入报废负责人id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="报废负责人名称" prop="declaredRespName">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredRespName"-->
<!--          placeholder="请输入报废负责人名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="报废负责人部门名称" prop="declaredRespDeptName">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredRespDeptName"-->
<!--          placeholder="请输入报废负责人部门名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最后使用人id" prop="declaredUserId">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredUserId"-->
<!--          placeholder="请输入最后使用人id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最后使用人名称" prop="declaredUserName">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredUserName"-->
<!--          placeholder="请输入最后使用人名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最后使用人部门id" prop="declaredUserDeptId">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredUserDeptId"-->
<!--          placeholder="请输入最后使用人部门id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最后使用人部门名称" prop="declaredUserDeptName">-->
<!--        <el-input-->
<!--          v-model="queryParams.declaredUserDeptName"-->
<!--          placeholder="请输入最后使用人部门名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:AssetDeclared:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:AssetDeclared:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:AssetDeclared:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:AssetDeclared:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="AssetDeclaredList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="自增id" align="center" prop="id" />
      <el-table-column label="报废资产id" align="center" prop="declaredAssetId" />
      <el-table-column label="报废资产名称" align="center" prop="declaredAssetName" />
      <el-table-column label="报废资产类别名称" align="center" prop="declaredAssetClassName" />
      <el-table-column label="品牌" align="center" prop="assetBrand" />
      <el-table-column label="规格型号" align="center" prop="assetModel" />
      <el-table-column label="数量" align="center" prop="declaredQuantity" />
      <el-table-column label="报废时间" align="center" prop="declaredTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.declaredTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报废原因" align="center" prop="declaredReason" />
      <el-table-column label="报废领用信息id" align="center" prop="declaredReceiveId" />
      <el-table-column label="报废负责人id" align="center" prop="declaredRespId" />
      <el-table-column label="报废负责人名称" align="center" prop="declaredRespName" />
      <el-table-column label="报废负责人部门id" align="center" prop="declaredRespDeptId" />
      <el-table-column label="报废负责人部门名称" align="center" prop="declaredRespDeptName" />
      <el-table-column label="最后使用人id" align="center" prop="declaredUserId" />
      <el-table-column label="最后使用人名称" align="center" prop="declaredUserName" />
      <el-table-column label="最后使用人部门id" align="center" prop="declaredUserDeptId" />
      <el-table-column label="最后使用人部门名称" align="center" prop="declaredUserDeptName" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:AssetDeclared:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:AssetDeclared:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改资产报废对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="报废资产id" prop="declaredAssetId">
          <el-input v-model="form.declaredAssetId" placeholder="请输入报废资产id" />
        </el-form-item>
<!--        <el-form-item label="报废资产名称" prop="declaredAssetName">-->
<!--          <el-input v-model="form.declaredAssetName" placeholder="请输入报废资产名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="报废资产类别名称" prop="declaredAssetClassName">-->
<!--          <el-input v-model="form.declaredAssetClassName" placeholder="请输入报废资产类别名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="品牌" prop="assetBrand">-->
<!--          <el-input v-model="form.assetBrand" placeholder="请输入品牌" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="规格型号" prop="assetModel">-->
<!--          <el-input v-model="form.assetModel" placeholder="请输入规格型号" />-->
<!--        </el-form-item>-->
        <el-form-item label="数量" prop="declaredQuantity">
          <el-input v-model="form.declaredQuantity" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="报废时间" prop="declaredTime">
          <el-date-picker clearable
            v-model="form.declaredTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报废时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报废原因" prop="declaredReason">
          <el-input v-model="form.declaredReason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="报废领用信息id" prop="declaredReceiveId">
          <el-input v-model="form.declaredReceiveId" placeholder="请输入报废领用信息id" />
        </el-form-item>
        <el-form-item label="报废负责人id" prop="declaredRespId">
          <el-input v-model="form.declaredRespId" placeholder="请输入报废负责人id" />
        </el-form-item>
<!--        <el-form-item label="报废负责人名称" prop="declaredRespName">-->
<!--          <el-input v-model="form.declaredRespName" placeholder="请输入报废负责人名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="报废负责人部门id" prop="declaredRespDeptId">-->
<!--          <el-input v-model="form.declaredRespDeptId" placeholder="请输入报废负责人部门id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="报废负责人部门名称" prop="declaredRespDeptName">-->
<!--          <el-input v-model="form.declaredRespDeptName" placeholder="请输入报废负责人部门名称" />-->
<!--        </el-form-item>-->
        <el-form-item label="最后使用人id" prop="declaredUserId">
          <el-input v-model="form.declaredUserId" placeholder="请输入最后使用人id" />
        </el-form-item>
<!--        <el-form-item label="最后使用人名称" prop="declaredUserName">-->
<!--          <el-input v-model="form.declaredUserName" placeholder="请输入最后使用人名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="最后使用人部门id" prop="declaredUserDeptId">-->
<!--          <el-input v-model="form.declaredUserDeptId" placeholder="请输入最后使用人部门id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="最后使用人部门名称" prop="declaredUserDeptName">-->
<!--          <el-input v-model="form.declaredUserDeptName" placeholder="请输入最后使用人部门名称" />-->
<!--        </el-form-item>-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="删除标志" prop="delFlag">-->
<!--          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAssetDeclared, getAssetDeclared, delAssetDeclared, addAssetDeclared, updateAssetDeclared } from "@/api/module/AssetDeclared";

export default {
  name: "AssetDeclared",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产报废表格数据
      AssetDeclaredList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        declaredAssetId: null,
        declaredAssetName: null,
        declaredAssetClassName: null,
        assetBrand: null,
        assetModel: null,
        declaredQuantity: null,
        declaredTime: null,
        declaredReason: null,
        declaredRespId: null,
        declaredRespName: null,
        declaredRespDeptName: null,
        declaredUserId: null,
        declaredUserName: null,
        declaredUserDeptId: null,
        declaredUserDeptName: null,
        declaredReceiveId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资产报废列表 */
    getList() {
      this.loading = true;
      listAssetDeclared(this.queryParams).then(response => {
        this.AssetDeclaredList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        declaredAssetId: null,
        declaredAssetName: null,
        declaredAssetClassName: null,
        assetBrand: null,
        assetModel: null,
        declaredQuantity: null,
        declaredTime: null,
        declaredReason: null,
        declaredRespId: null,
        declaredRespName: null,
        declaredRespDeptId: null,
        declaredRespDeptName: null,
        declaredUserId: null,
        declaredUserName: null,
        declaredUserDeptId: null,
        declaredUserDeptName: null,
        remark: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        declaredReceiveId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资产报废";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAssetDeclared(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改资产报废";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAssetDeclared(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAssetDeclared(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除资产报废编号为"' + ids + '"的数据项？').then(function() {
        return delAssetDeclared(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/AssetDeclared/export', {
        ...this.queryParams
      }, `AssetDeclared_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
